1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Foundation
import UIKit
class DraggableImg: UIImageView {
var originalPosition: CGPoint!
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
originalPosition = self.center
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
let position = touch.locationInView(self.superview)
self.center = CGPointMake(position.x, position.y)
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.center = originalPosition
}
}
Prev Next